/**
 * 标准列表
 * @author linfeng
 * @date 2019/12/24
 */
var $ = layui.$;
layui.define(['index', 'form', 'table', 'laypage', 'layedit', 'laydate'], function (exports) {
    var layer = layui.layer;
    var table = layui.table;
    var laypage = layui.laypage;
    table.init('zmn-table', {
        toolbar: "#zmn-table-tool",
        page: true,
        defaultToolbar: ['filter'],
        limit: json.pageSize || 50,
        height: 'full-149',
    });
    laypage.render(layui.$.extend({limits: [10, 20, 30, 40, 50, 100]}, zmnOmsPage.laypageOptions(json)));

    let promChannels = new Array();
    table.on("checkbox(zmn-table)", function () {
        promChannels = table.checkStatus('zmn-table').data.map(function (obj) {
            let promChannel = {
                channelId: obj.channelId,
                channelName: obj.name
            };
            return promChannel;
        });
    });

    table.on("toolbar(zmn-table)", function (obj) {
        if (obj.event == 'add') {
            if (promChannels.length === 0) {
                layer.msg("请选择至少一条数据！", {icon: 2});
                return false;
            }
            let filterChannel = new Array()
            let json = window.sessionStorage.getItem("list_channel_table_data")
            let channelListTableData = JSON.parse(json) || []
            let idx = channelListTableData.map(x => {
                return x.channelId
            })
            promChannels.filter(x => {
                if (idx.includes(x.channelId)) {
                    filterChannel.push(x.channelName)
                }
            })
            if (filterChannel.length > 0) {
                layer.msg("渠道：[" + filterChannel.join(",") + "]已经存在，请重新选择！", {icon: 2});
                return false;
            }
            window.sessionStorage.setItem("cooperation_checked_row", JSON.stringify(promChannels));
            zmnLayUtil.closeThisIframeMsg(parent, "添加成功！", "zmn-cooperation-table");
        }
    });

    //对外暴露的接口
    exports('zmn_oms_conf_cooperation_list');


});

